home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / julienne.lwm < prev    next >
Text File  |  1993-12-13  |  3KB  |  171 lines

  1. /* CMD: Julienne
  2.  *
  3.  * Finely slice an object along an axis.  This is a useful precursor
  4.  * to bend.
  5.  */
  6. syscode = "Julienne"
  7. sysnam = "Julienne"
  8. statfil = 'T:julienne.state'
  9. version = 'Julienne v1.0'
  10.  
  11.     /* Boilerplate.
  12.      */
  13.     mxx="LWModelerARexx.port"
  14.     signal on error
  15.     signal on syntax
  16.     mxx_add = addlib(mxx,0)
  17.   call addlib "rexxsupport.library", 0, -30, 0
  18.     call main
  19.     if (mxx_add) then call remlib(mxx)
  20.     exit
  21.  
  22.     syntax:
  23.     error:
  24.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  25.     if (mxx_add) then call remlib(mxx)
  26.     exit
  27.  
  28.  
  29.  
  30. MAIN:
  31.  
  32. fg = curlayer()
  33. emp = emptylayers()
  34. if (words(emp) = 0) then do
  35.     call notify(1,"!Need a background layer for scratch work.")
  36.     return
  37. end
  38. temp = word(emp,1)
  39.  
  40. if (setup() = 0) then return
  41.  
  42.  
  43. /* Compute transpositions for selected axis.  Vectors are transposed
  44.  * with xr when coming from Modeler, and transposed with xf when going
  45.  * out to Modeler.  Internally, we think of X as the slice axis, and
  46.  * Z as the drill axis.
  47.  */
  48. select
  49.     when (axis = 1) then do
  50.     xf = 1 2 3
  51.     xr = 1 2 3
  52.     end
  53.     when (axis = 2) then do
  54.     xf = 2 1 3
  55.     xr = 2 1 3
  56.     end
  57.     otherwise do
  58.     xf = 2 3 1
  59.     xr = 3 1 2
  60.     end
  61.     end
  62.  
  63. /* Get bounding box for fg data transposed into local space.
  64.  */
  65. parse value boundingbox() with n x1 x2 y1 y2 z1 z2 .
  66. if (n = 0) then return
  67. lo = xpose(x1 y1 z1, xr)
  68. hi = xpose(x2 y2 z2, xr)
  69.  
  70. /* Compute ranges for x and y.  Add small offsets to make our values
  71.  * overlap the actual bounds.
  72.  */
  73. x1 = word(lo,1)
  74. x2 = word(hi,1)
  75. d = (x2 - x1) / 101
  76. x1 = x1 - d
  77. x2 = x2 + d
  78. xw = (x2 - x1) / divs
  79.  
  80. y1 = word(lo,2)
  81. y2 = word(hi,2)
  82. d = (y2 - y1) / 3
  83. y1 = y1 - d
  84. y2 = y2 + d
  85.  
  86. /* Goto background layer and build our slicing blades.
  87.  */
  88. call setlayer(temp)
  89. call add_begin()
  90. x0 = x1 + xw
  91. do i=1 to divs/2
  92.     i1 = add_point(xpose(x0 y1 0, xf))
  93.     i2 = add_point(xpose(x0 y2 0, xf))
  94.     x0 = x0 + xw
  95.     i3 = add_point(xpose(x0 y2 0, xf))
  96.     i4 = add_point(xpose(x0 y1 0, xf))
  97.     x0 = x0 + xw
  98.  
  99.     call add_polygon(i1 i2 i3 i4)
  100. end i
  101. call add_end()
  102.  
  103. /* Perform the slice and remove the blades.
  104.  */
  105. call setlayer(fg)
  106. call setblayer(temp)
  107. call axisdrill('slice', word('x y z', word(xr, 3)))
  108. call setlayer(temp)
  109. call cut()
  110. call setlayer(fg)
  111.  
  112. return
  113.  
  114.  
  115.  
  116. SETUP:
  117.  
  118. /* Setup state variables, reading stored ones, if any.
  119.  */
  120. axis = 1
  121. divs = 20
  122. if (exists(statfil)) then do
  123.     if (~open(state, statfil, 'R')) then break
  124.     if (readln(state) ~= version) then break
  125.     parse value readln(state) with axis divs .
  126.     call close state
  127. end
  128.  
  129. /* Query user for their function and area to evaluate.
  130.  */
  131. call req_begin sysnam
  132.  
  133. id_axis = req_addcontrol("Axis", 'c', 'X Y Z')
  134. id_divs = req_addcontrol("Divisions", 'n')
  135.  
  136. call req_setval id_axis, axis
  137. call req_setval id_divs, divs, 20
  138.  
  139. if (~req_post()) then do
  140.     call req_end
  141.     return 0
  142. end
  143.  
  144. axis = req_getval(id_axis)
  145. divs = req_getval(id_divs) % 1
  146.  
  147. call req_end
  148.  
  149. /* Save state now, in case something fails.
  150.  */
  151. if (open(state, statfil, 'W')) then do
  152.     call writeln state, version
  153.     call writeln state, axis divs
  154.     call close state
  155. end
  156.  
  157. return 1
  158.  
  159.  
  160. /* Transpose the positions in a vector by the indices in x.
  161.  * If the vector is X Y Z and the transposition is 2 3 1, then
  162.  * the resultant vector is Y Z X.
  163.  */
  164. Xpose: procedure
  165.     arg v, x
  166.     vv = ''
  167.     do i=1 to 3
  168.     vv = vv word(v,word(x,i))
  169.     end i
  170.     return vv
  171.